import {
	mapGetters,
	mapState
} from "vuex";
export default {
	data() {
		shareImgArr: []
	},
	onLoad(){
		this.getShareImg();
	},
	methods: {
		getShareImg() {
			// 获取分享图
			this.$request.get(`shopapi/home/slideshow_list?type=9`).then(res => {
				console.log("分享图" + res.data.data.lists);
				this.shareImgArr = res.data.data.lists;
			})
		},
		getRandomElement(arr) {
			const randomIndex = Math.floor(Math.random() * arr.length);
			return arr[randomIndex];
		}
	},
	computed: {
		...mapGetters([
			"isLogin",
			"themeName",
			"themeColor",
			"userInfo",
			"appConfig",
		]),
	},
	// 全局配置分享
	onShareAppMessage() {
		console.log(this.userInfo);
		console.log("全局分享123");
		let titleArr = [];
		let title1 = '给你推荐一个攒劲的商城！';
		let title2 = '邀请加入CHO健康生活圈！';
		let title3 = '做家庭健康的第一责任人！';
		titleArr.push(title1);
		titleArr.push(title2);
		titleArr.push(title3);
		const randomIndex = Math.floor(Math.random() * titleArr.length);
		const {
			share_image,
			share_intro,
			share_title
		} = this.appConfig;
		const {
			code
		} = this.userInfo;
		console.log(code)

		const share = {
			title: titleArr[randomIndex],
			path: `/pages/index/index?invite_code=${code}`,
			imageUrl: this.getRandomElement(this.shareImgArr).img_url,
		};
		return share;
	},
	onShareTimeline() {
		const {
			share_image,
			share_intro,
			share_title
		} = this.appConfig;
		const {
			code
		} = this.userInfo;
		const share = {
			title: share_title,
			imageUrl: 'https://cdn.zkjialan.com/img/index/share.jpg',
		};
		return share;
	},
};